package guoanmaker.operator.business.service;

import guoanmaker.operator.business.model.OperatorSpace;
import guoanmaker.operator.business.repository.OperatorSpaceRepository;
import guoanmaker.operator.helper.common.AjaxJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

import javax.transaction.Transactional;

/**
 *  
 *
 * @ClassName: OperatorSpaceService 
 * @Description: OperatorSpaceService 
 * @author: huZhaoyu 
 * @date 2017/6/28 下午2:56 
 */
@Service
public class OperatorSpaceService implements OperatorSpaceServiceInterface {
    private final OperatorSpaceRepository operatorSpaceRepository;

    @Autowired
    public OperatorSpaceService(OperatorSpaceRepository operatorSpaceRepository) {
        this.operatorSpaceRepository = operatorSpaceRepository;
    }

    @Override
    @Transactional
    public OperatorSpace saveSpace(OperatorSpace operatorSpace) {
        return operatorSpaceRepository.save(operatorSpace);
    }

    @Override
    public List<OperatorSpace> getAllSpace() {
        return operatorSpaceRepository.findAll();
    }

    @Override
    public Page<OperatorSpace> getAllSpaceByPage(Integer page, Integer size) {
        return operatorSpaceRepository.findAll(new PageRequest(page, size));
    }

    @Override
    @Transactional
    public void deleteSpaceById(String id) {
        operatorSpaceRepository.delete(id);
    }

    @Override
    public OperatorSpace getSpaceById(String id) {
        return operatorSpaceRepository.findOne(id);
    }

    @Override
    public List<OperatorSpace> getAllBySpaceTitleOrderByCreateDate(String spaceTitle) {
        return operatorSpaceRepository.findBySpaceTitleContainingOrderByCreateDateDesc(spaceTitle);
    }
}
